/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.group4.highschoolportal.student.backingbean;

import com.group4.controller.LessonFacade;
import com.group4.controller.StudentFacade;
import com.group4.entity.Course;
import com.group4.entity.Lesson;
import com.group4.entity.Student;
import com.group4.highschoolportal.loginBean.IndexBackingBean;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Victor Cernea
 */
@ManagedBean
@SessionScoped
public class StudentBackingBean implements Serializable {

    @EJB
    private LessonFacade lessonDb;
    private Student stud;
    private List<Lesson> lessons;

    /** Creates a new instance of StudentBackingBean */
    public StudentBackingBean() {
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        stud = (Student) session.getAttribute("user");
        lessons = new ArrayList<Lesson>();

    }

    @PostConstruct
    private void init() {
        List<Course> courses = stud.getsCourses();
        for (Course c : courses) {
            for (Lesson l : c.getLesson()) {
                lessons.add(l);
            }
        }
    }

    public Student getStud() {
        return stud;
    }

    public void setStud(Student stud) {
        this.stud = stud;
    }

    public List<Lesson> getLessons() {
        return lessons;
    }

    public void setLessons(List<Lesson> lessons) {
        this.lessons = lessons;
    }
}
